using System;
using System.Collections.Generic;
using EmailJabber.Logic.Logic.BusinessLogic;

namespace EmailJabber.Logic.Commands.Base
{
    /// <summary>This class declares an interface for executing an operation
    ///Class added from the design pattern:Command</summary>
    public abstract class CommandBase
    {
        private string _description;
        private List<Guid> tags;
        protected string[] _aliaces;
        
        /// <summary>
        /// get or set command name
        /// </summary>
        public string Description
        {
            get
            {
                if (string.IsNullOrEmpty(_description))
                {
                    _description = GetDecription();
                }
                return _description;
            }
        }

        private Guid _id = Guid.Empty;

        public Guid Id
        {
            get
            {
                if (_id.Equals(Guid.Empty))
                {
                    _id = GetId();
                }
                return _id;
            }
        }

        public string[] Aliaces
        {
            get { return _aliaces; }
        }

        public List<Guid> Tags
        {
            get
            {
                if(tags == null)
                {
                    tags = GetTags();
                }
                return tags;
            }
        }
        
        int _accessLevel = 0;
        public int AccessLevel{get{return _accessLevel;}}
        
        protected virtual List<Guid> GetTags()
        {
        	return new List<Guid>();
        }

        protected abstract string GetDecription();
        protected abstract Guid GetId();


        /// <summary></summary>
        /// <returns></returns>
        public void Execute(MessageIM comnd)
        {
            try
            {
                ExecuteSafe(comnd);
            }
            catch (Exception ex)
            {
                BL.Instance.SendMessageToAdmin(ex.ToString());
            }
        }

        protected abstract void ExecuteSafe(MessageIM comnd);
    }
}